package com.cqie.rbac.controller;


import cn.hutool.db.Page;
import com.cqie.rbac.bo.ClassBo;
import com.cqie.rbac.entity.Classes;
import com.cqie.rbac.entity.TestDepartment;
import com.cqie.rbac.entity.UserClassView;
import com.cqie.rbac.mapper.ClassesMapper;
import com.cqie.rbac.service.IUserClassViewService;
import com.cqie.rbac.util.MyPageHelper;
import com.cqie.rbac.util.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * VIEW 前端控制器
 * </p>
 *
 * @author 单机吧
 * @since 2021-10-12
 */
@Api(tags = "班级管理")
@RestController
@RequestMapping("/class")
public class UserClassViewController {

    @Autowired
    private IUserClassViewService iUserClassViewService;

    @Autowired
    private ClassesMapper classesMapper;

    @ApiOperation("查询班级列表")
    @GetMapping("/getClassList")
    public Result<PageInfo<UserClassView>> getClassList(ClassBo bo){
        List<UserClassView> userClassViews = iUserClassViewService.getClassList(bo);
        return Result.ok().data(MyPageHelper.returnPage(userClassViews));
    }

    @ApiOperation("新增班级")
    @PostMapping("/InsertClass")
    public Result InsertClass(Classes classes){
        classesMapper.insert(classes);
        return Result.ok();
    }

    @ApiOperation("删除班级")
    @PostMapping("/DeleteClass")
    public Result DeleteClass(Integer id){
        classesMapper.deleteByPrimaryKey(id);
        return Result.ok();
    }

    @ApiOperation("修改班级")
    @PostMapping("/UpdateClass")
    public Result UpdateClass(Classes classes){
        classesMapper.updateByPrimaryKeySelective(classes);
        return Result.ok();
    }

}
